package com.my.aslife.aop;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.my.aslife.module.common.Constant;
import com.my.aslife.module.common.RedisConstant;
import com.my.aslife.module.entity.Sensitive;
import com.my.aslife.service.impl.SensitiveServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Set;

/**
 * @author mayuan
 * @description TODO
 */
@Component
@Aspect
@Slf4j
public class UpdateSensitiveAop {

    @Autowired
    private SensitiveServiceImpl sensitiveService;

    @Pointcut("@annotation(com.my.aslife.aop.UpdateSensitive)")
    public void updateSensitivePointCut() {
    }

    @Around("updateSensitivePointCut()")
    public Object loglog(ProceedingJoinPoint pjp) throws Throwable {
        Object arg = pjp.getArgs()[0];
        if (arg instanceof Sensitive) {
            Sensitive sensitive = (Sensitive) pjp.getArgs()[0];
            sensitive.setCreateTime(LocalDateTime.now());
        }
        Object result = pjp.proceed();
        sensitiveService.initSensitive();
        return result;
    }
}
